package com.zelin.web.controller;

import com.zelin.web.exception.MyException;
import com.zelin.pojo.Student;
import com.zelin.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ------------------------------
 * 功能：
 * 作者：WF
 * 微信：hbxfwf13590332912
 * 创建时间：2021/10/18-14:53
 * ------------------------------
 */
@Controller
@RequestMapping("student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    //1. 查询所有学生
    @GetMapping("list")
    @ResponseBody
    public List<Student> findAll(){
        return studentService.findAll();
    }

    @GetMapping("getName")
    public void getName(String name,String password){
        if("aaa".equals(name)){
            throw new MyException("用户名不正确!");
        }else if("111".equals(password)){
            throw new MyException("密码不正确！");
        }else{
            throw new RuntimeException("其它异常！");
        }
    }
}
